package laf.agents;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import jade.core.AID;
import laf.env.Attribute;
import laf.env.Enviroment;

public class LanguageSymbolGroundingHistory implements Serializable {
	private AID agent;
	private Map<Long, LanguageSymbolDictionary> historyMap = new HashMap<Long, LanguageSymbolDictionary>();

	private Collection<Attribute> attributes;
	
	private transient ChangeListener listener;

	public void setListener(ChangeListener listener) {
		this.listener = listener;
	}

	public ChangeListener getListener() {
		return listener;
	}

	public LanguageSymbolGroundingHistory() {
		setAttributes(Enviroment.getInstance().getAttributes());
	}

	public LanguageSymbolGroundingHistory(AID agent) {
		this();
		this.agent = agent;
	}

	public boolean contains(long time) {
		return historyMap.containsKey(time);
	}

	public LanguageSymbolDictionary get(long time) {
		return historyMap.get(time);
	}

	public boolean isEmpty() {
		return historyMap.isEmpty();
	}

	public void add(long time, LanguageSymbolDictionary dictionary) {
		dictionary = new LanguageSymbolDictionary(dictionary);
		historyMap.put(time, dictionary);
		if (listener != null) {
			listener.stateChanged(new ChangeEvent(this));
		}
	}

	public int size() {
		return historyMap.size();
	}

	public AID getAgent() {
		return agent;
	}

	public void setAgent(AID agent) {
		this.agent = agent;
	}

	public void setAttributes(Collection<Attribute> attributes) {
		this.attributes = new HashSet<Attribute> (attributes);
	}

	public Collection<Attribute> getAttributes() {
		return attributes;
	}

}
